<template>
  <div class="topicDetailsMainL" id="topicDetailsMainL">
    <div>
      <div class="topicLeft">
        <template v-if="infoData&&!loading">
          <div class="wrapL">
            <div class="imgBox">
            <el-popover
              placement="right"
              width="200"
              popper-class="big_img"
              :visible-arrow="false"
              trigger="click">
              <img :src="infoData.thumPic?infoData.thumPic:noTopicImgUrl" slot="reference"/>
              <img :src="infoData.thumPic?infoData.thumPic:noTopicImgUrl" />
            </el-popover>
              <!-- <img :src="infoData.thumPic" v-if="infoData.thumPic" /> -->
            </div>
            <p>{{ infoData.title }}</p>
          </div>
          <div>
            <div>
              <p>发起人</p>
              <p class="nickname">{{ infoData.nickname }}</p>
            </div>
            <div>
              <p>参与人数</p>
              <p>{{ format_num(infoData.useCount) }}</p>
            </div>
            <div>
              <p>播放量</p>
              <p>{{ format_num(infoData.playCount) }}</p>
            </div>
          </div>
        </template>
        <div
          v-loading="loading"
          v-if="loading"
          class="loading"
          element-loading-text="拼命加载中..."
          element-loading-spinner="el-icon-loading"
        ></div>
        <button
          v-if="infoData&&!infoData.isCollect"
          @click="addStar(infoData.topicId)"
        >添加收藏</button>
        <button
          v-if="infoData&&infoData.isCollect&&!loading"
          @click="cancelVideoStar(infoData.topicId)"
        >已收藏</button>
      </div>
    </div>
    <div id="collectRoot">
      <div class="rightBox">
        <div class="btn_group">
          <button
            :class="{ active: input_btn == '0' }"
            @click="input_btn = '0'"
          >数据分析</button>
        </div>
        <div class="rig_box">
          <div class="rightBox-content">
            <dataInfo ref="dataInfo" :title="infoData.title" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import dataInfo from './dataInfo';
import noTopicImg from "@/assets/meng/no_topic.png";
export default {
  props: [],
  data() {
    return {
      loading: false,
      add: false,
      input_btn: 0,
      noTopicImgUrl:noTopicImg,
      infoData: []
    };
  },
  components: { dataInfo },
  computed: {},
  created() {
    this.getDetailsData();
  },
  mounted() {},
  watch: {},
  methods: {
    // 基本信息
    getDetailsData() {
      let that = this;
      console.log(that.$route.params.id);
      this.loading = true;
      that.$axios
        .get('/api/topic/GetTopicDetail?topicId=' + that.$route.params.id)
        // .get('/api/topic/GetTopicDetail?topicId=' + 1380949933)
        .then(res => {
          this.loading = false;
          if (res.data.code == 0) {
            that.infoData = res.data.data;
            // this.$refs.dataInfo.GetTopicAwemes1();
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 收藏话题
    addStar(id, item) {
      let that = this;
      that.$axios
        .post(
          '/api/collection/InsertCollection',
          {
            CollectId: id,
            Module: 4 //模块 1达人 2视频 3音乐 4话题 5商品
          },
          {
            cancelToken: new that.$axios.CancelToken(function executor(c) {
              if (that.cancel01 != null) {
                that.cancel01();
              }
              that.cancel01 = c;
            })
          }
        )
        .then(res => {
          if (res.data.code == 0) {
            this.$message({
              message: '收藏成功！',
              type: 'success',
              duration: 2000
            });
            this.infoData.isCollect = 1;
          } else {
            this.$message({
              message: '收藏失败！',
              type: 'error',
              duration: 2000
            });
          }
        })
        .catch(err => {
          this.$message({
            message: '收藏失败！',
            type: 'error',
            duration: 2000
            // offset: '400',
          });
          console.log(err);
        });
    },
    // 取消收藏视频
    cancelVideoStar(id) {
      let that = this;
      that.$axios
        .post(
          '/api/collection/CancelCollection',
          {
            CollectId: id.toString(),
            Module: 4 //模块 1达人 2视频 3音乐 4话题 5商品
          },
          {
            cancelToken: new that.$axios.CancelToken(function executor(c) {
              if (that.cancel04 != null) {
                that.cancel04();
              }
              that.cancel04 = c;
            })
          }
        )
        .then(res => {
          if (res.data.code == 0) {
            this.$message({
              message: '取消收藏成功！',
              type: 'success',
              duration: 2000
            });
            this.infoData.isCollect = 0;
          } else {
            this.$message({
              message: '取消收藏失败！',
              type: 'error',
              duration: 2000
            });
          }
        })
        .catch(err => {
          this.$message({
            message: '取消收藏失败！',
            type: 'error',
            duration: 2000
          });
          console.log(err);
        });
    }
  }
};
</script>

<style lang="less" scoped>
.topicDetailsMainL {
  margin-left: @margin-num;
  margin-right: @margin-num;
  margin-top: @margin-num;
  overflow: hidden;
  display: flex;
  height: calc(100vh - 94px);
  display: flex;
  .topicLeft {
    text-align: center;
    width: 300px;
    // min-height: 277px;
    background-color: #ffffff;
    border-radius: 4px;
    box-sizing: border-box;
    padding: 20px;
    overflow: hidden;
    > div {
      text-align: left;
      &:nth-child(1) {
        display: flex;
        margin-bottom: 30px;
        .imgBox {
          margin-right: 10px;
          width: 50px;
          height: 50px;
          flex: 0 0 50px;
          border-radius: 6px;
          overflow: hidden;
          cursor: pointer;
          img {
            width: 100%;
            height: 100%;
          }
        }
        > p {
          // align-self: center;
          width: 206px;
          font-size: 16px;
          font-weight: 600;
          color: #222222;
          margin-top: 5px;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          overflow: hidden;
        }
      }
      &:nth-child(2) {
        border-bottom: 1px solid #efefef;
        > div {
          display: flex;
          > p {
            font-size: 12px;
            color: #888888;
            margin-bottom: 20px;
            width: 75px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
          > span {
            font-size: 13px;
            color: #222222;
          }
        }
      }
    }
    > button {
      justify-content: center;
      width: 80px;
      height: 32px;
      border-radius: 4px;
      border: solid 1px #fd7f2c;
      margin-top: 15px;
      font-size: 14px;
      color: #fd7f2c;
      line-height: 28px;
    }
  }
  #collectRoot {
    box-sizing: border-box;
    flex: 1;
    height: 100%;
    overflow: hidden;
    // margin-top: @margin-num;
    margin-left: @margin-num;
    // margin-right: @margin-num;
    background-color: #f1f1f1;
    .rig_box {
      width: 100%;
      height: calc(100% - 50px);
      border-radius: 4px;
      padding: 20px 0 3px;
      margin-top: 10px;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      background: #fff;
      overflow: hidden;
    }
    // .rig_box {
    //   width: 100%;
    //   height: calc(100% - 50px);
    //   border-radius: 4px;
    //   padding: 20px 0px 3px 0px;
    //   margin-top: 10px;
    //   box-sizing: border-box;
    //   background: #fff;
    //   -webkit-box-sizing: border-box;
    //   overflow: hidden;
    // }
    .rightBox {
      width: 100%;
      position: relative;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      height: 100%;
      -webkit-box-flex: 1;
      -ms-flex: 1;
      flex: 1;
      border-radius: 6px;
      .btn_group {
        text-align: left;
        .active {
          background-color: #fd7f2c;
          color: #ffffff !important;
        }
        button {
          font-size: 14px;
          color: #555;
          padding-left: 23px;
          padding-right: 23px;
          height: 40px;
          background-color: #fff;
          border-radius: 4px;
          margin-right: 7px;
          font-weight: 600;
        }
      }
    }
    .rightBox-content {
      position: relative;
      background-color: #ffffff;
      border-radius: 6px;
      // margin-top: 10px;
      height: calc(100% - 20px);
      // height: 100%;
      overflow: scroll;
      overflow-x: hidden;
    }
  }
  .nickname {
    width: 120px !important;
  }
}
</style>
